package com.power.algorithm;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

/**
 * @description:
 * @author: jiangnan
 * @time: 2021/6/17 4:47 下午
 */
public class Solution1 {

    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap();
        for (int i = 0; i < nums.length; i++) {
            if (map.containsKey(target - nums[i])) {
                return new int[]{i, map.get(target - nums[i])};
            } else {
                map.put(nums[i], i);
            }
        }
        return new int[]{-1, -1};
    }

    public static void main(String[] args) {
        int [] nums = new int[]{1,3,4,6,15,9};
        Solution1 solution1 = new Solution1();
        System.out.println(Arrays.toString(solution1.twoSum(nums, 12)));
    }
}
